<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Commande
 *
 * @author Caroline
 */
class Commande {
    private $id;
    private $tva;
    private $ht;
    private $lesArticles;
    private $nbArticles;

    //constructeur
    function __construct($id, $tva, $ht) {
        $this->id = $id;
        $this->tva = $tva;
        $this->ht = $ht;
        $this->lesArticles = Array();
        $this->nbArticles = 0;
    }

    //accesseurs
    public function getId() {
        return $this->id;
    }

    public function getTva() {
        return $this->tva;
    }

    public function getHt() {
        return $this->ht;
    }
    
    public function getLesArticles() {
        return $this->lesArticles;
    }

    
    //modificateurs
    public function setTva($tva) {
        $this->tva = $tva;
    }

    public function setHt($ht) {
        $this->ht = $ht;
    }
    
    public function setLesArticles($lesArticles) {
        $this->lesArticles = $lesArticles;
    }
    
    public function ajoutArticle($unArticle) {
        $this->nbArticles = $this->nbArticles + 1;
        $this->lesArticles[$this->nbArticles] = $unArticle;
    }
    
    public function chargerLesArticles(Bdd $sql){
        $reqArticle = "SELECT art_id, art_libelle, art_prixLocation, art_image, art_desc,art_caution, art_couleur, art_dimensions, art_poids, art_stock, art_marque 
                       FROM article, commande, comporter
                       WHERE com_article = art_id
                       AND com_commande = com_id
                       AND com_id = ".$this->id;

        $lesArticles = $sql->query($reqArticle);
        foreach($lesArticles as $lArticle){
            $unArticle = new Article($lArticle["art_id"],
                                     $lArticle["art_libelle"],
                                     $lArticle["art_prixLocation"],
                                     $lArticle["art_image"],
                                     $lArticle["art_desc"],
                                     $lArticle["art_caution"],
                                     $lArticle["art_couleur"],
                                     $lArticle["art_dimensions"],
                                     $lArticle["art_poids"],
                                     $lArticle["art_stock"],
                                     $lArticle["art_marque"]);

            $this->ajoutArticle($unArticle);
        }
    }
    
    public function modifierCommande(Bdd $sql){            
        $maj = "UPDATE commande
                WHERE com_id ='$this->id',
                SET com_tva ='$this->tva',
                    com_ht ='$this->ht'";

        $sql->query($maj);
    }  
    
    public function ajoutCommande(Bdd $sql, $pNum_CLI){        
        $new = "INSERT INTO commande
                VALUES ('$this->id',
                        '$pNum_CLI',
                        '$this->tva',
                        '$this->ht')";

        $sql->query($new);
    }
}
?>
